<template>
  <div class="top-container borderStyle">
    <div class="blueTitleStyle betweenbox">
      <span>实时告警信息</span>
      <span class="detail centerbox" @click="toDetail">详情</span>
    </div>
    <div
      class="content-container"
      v-loading="loading"
      element-loading-text="数据加载中"
      element-loading-spinner="el-icon-loading"
      element-loading-background="rgba(0, 0, 0, 0.8)"
    >
      <div v-for="(item,index) in gjDataList" :key="index">
        <div>
          <span class="redicon"></span>
          <span>{{item.GJSJ}}</span>
        </div>
        <div class="content">{{item.SJMS}}</div>
      </div>
    </div>
    <el-dialog title="历史信息" :visible.sync="visible" width="80%">
      <Detail />
      <iframe class="iframe" frameborder="0"></iframe>
    </el-dialog>
    <!-- 一直弹框的信息 -->
    <el-dialog :title="dialogData.BDZMC" :visible.sync="ifoVisible" width="80%">
      <message :dialogData="dialogData" />
      <iframe class="iframe" frameborder="0"></iframe>
    </el-dialog>
    <!-- 一直弹框的信息 -->

    <!-- <viewer :images="viewerImageUrl" @inited="inited">
      <img
        :src="img"
        :key="index"
        v-show="false"
        :alt="altTitle"
        v-for="(img,index) in viewerImageUrl"
      />
    </viewer>-->
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import Detail from "../Detail/index.vue";
import message from "../message/index.vue";
import lodash from "lodash";
import Viewer from "v-viewer";

@Component({
  components: { Detail, message },
})
export default class extends Vue {
  loading: boolean = false;
  visible: boolean = false;
  ifoVisible: boolean = false;
  gjDataList = [
    // {
    //   BDZMC: "110kV商西变电站",
    //   CN: 1,
    //   GJSJ: "2019-11-29 15:11:52",
    //   ID: "97A1EF1125DC6AA8E053A618C10AC8AF",
    //   IMAGE: 0,
    //   IMAGEURL:
    //     "http://10.192.34.107:10002/img/2019/1129/100435539/dde9ec2a96324bc7a72e63cbab43f08a.jpg",
    //   SJMS: "站用变室发现小动物入侵，请运维人员立即排查",
    // },
  ];
  oldGjDataList = []; //旧数据
  viewerImageUrl = []; //弹出图片的URL
  altTitle = ""; //弹出图片的标题

  mounted() {
    this.queryLatestAlarmInfo();
    this.setIntervalTime();
  }
  beforeDestroy() {
    this.clearIntervalTime();
  }
  // 定时器
  IntervalTime = null;
  // 设置定时器
  setIntervalTime() {
    this.clearIntervalTime();
    this.IntervalTime = window.setInterval(() => {
      this.queryLatestAlarmInfo();
    }, 20000);
  }
  // 清除定时器
  clearIntervalTime() {
    if (this.IntervalTime) {
      window.clearInterval(this.IntervalTime);
      this.IntervalTime = null;
    }
  }
  // 显示详情信息
  toDetail() {
    this.visible = true;
  }
  viewer: any = null;
  // $refs!: {
  //   viewer: Viewer;
  // };
  // 初始化图片放大
  inited(viewer) {
    this.viewer = viewer;
  }
  dialogData = {};
  // 是否弹出图片
  setDislogImg() {
    
    if (this.oldGjDataList.length && this.gjDataList.length) {
      let oldObj = {};
      this.oldGjDataList.forEach((v) => {
        oldObj[v.GJSJ] = v;
      });
      let dialogData = null;
      
      this.gjDataList.forEach((v) => {
        if (!oldObj[v.GJSJ]) {
          // this.viewerImageUrl = [v.IMAGEURL];
          // this.altTitle = v.BDZMC;
          // this.viewer.show();
          // this.addInframe();
          dialogData = v;
        }
      });
      if (dialogData) {
        this.dialogData = dialogData;
        this.ifoVisible = true;
      }
    }
  }
  // 数据请求
  queryLatestAlarmInfo() {
    this.loading = true;
    let data = { rows: 10 };
    this.oldGjDataList = lodash.cloneDeep(this.gjDataList);
    (this as any).$services
      .queryLatestAlarmInfo({ data })
      .then((result: any) => {
        this.loading = false;
        this.gjDataList = result.data;
        console.log(this.gjDataList);
        
        this.setDislogImg();
      })
      .catch((err: object) => {
        this.loading = false;
        console.log(err);
      });
  }
  addInframe() {
    // let el-picker-panel el-date-picker el-popper
    window.setTimeout(() => {
      let pickerArr = document.querySelectorAll(".viewer-container");
      pickerArr.forEach((item) => {
        let width = item.clientWidth;
        let height = item.clientHeight;
        let iframe: any = item.querySelector("iframe");
        if (!iframe) {
          iframe = document.createElement("iframe");
          item.appendChild(iframe);
        }
        iframe.style.width = width + "px";
        iframe.style.height = height + "px";
        iframe.style.position = "absolute";
        iframe.style.top = "0px";
        iframe.style.left = "0px";
        iframe.style.zIndex = 1;
        iframe.style.zIndex = 1;
        iframe.style.pointerEvents = "none";
      });
    }, 100);
  }
}
</script>

<style lang="scss" scoped>
.top-container {
  width: 100%;
  height: 100%;
  .detail {
    border: 1px solid rgba(5, 180, 255, 1);
    width: 0.8rem;
    height: 0.27rem;
    font-size: 0.16rem;
    border-radius: 0.02rem;
    cursor: pointer;
  }
  .redicon {
    display: inline-block;
    width: 0.12rem;
    height: 0.12rem;
    border-radius: 50%;
    background: #dd2020;
    margin-right: 0.06rem;
  }
  .content-container {
    margin-top: 0.1rem;
    padding: 0.1rem 0.1rem;
    overflow: auto;
    height: calc(100% - 0.5rem);
  }
  .content {
    padding: 0.06rem 0.16rem 0.2rem 0.16rem;
  }
  .iframe {
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0px;
    left: 0px;
    z-index: 1;
    opacity: 0.1;
    background: none;
    pointer-events: none;
  }
}
</style>

